<template>
  <!-- 编辑备注信息弹窗 -->
  <el-dialog class="pick-dialog" title="编辑" :visible.sync="dialogVisible" :close-on-click-modal="false" width="600px">
    <div class="form-box">
      <el-form :model="ruleForm" ref="ruleForm" :inline="true" label-width="auto" :rules="rules" class="demo-ruleForm new_form_box">
        <el-form-item label="销售人:" prop="saleUserId">
          <el-select filterable v-model="ruleForm.saleUserId" placeholder="请选择销售人" @change="buyerChange">
            <el-option v-for="(item ,key) in yuangongList" :key="key" :label="item.nickName" :value="item.userId" />
          </el-select>
        </el-form-item>

        <el-form-item label="真实游戏账号:" prop="realAccountNumber">
          <el-input placeholder="请输入真实游戏账号" type="text" style="width: 200px;" v-model="ruleForm.realAccountNumber"></el-input>
        </el-form-item>

        <el-form-item label="换绑状态:" prop="changePhoneState">
          <el-select v-model="ruleForm.changePhoneState" placeholder="请选择换绑状态">
            <el-option label="未换绑" :value="1" />
            <el-option label="已换绑" :value="2" />
          </el-select>
        </el-form-item>
        <el-form-item label="换绑手机:" prop="changeTel">
          <el-input placeholder="请输入换绑手机" type="text"  v-model="ruleForm.changeTel"></el-input>
        </el-form-item>
        <el-form-item label="换绑截图" label-width="70px" prop="changePhoneImg" class="row">
          <uploadImageOne v-model="ruleForm.changePhoneImg" @change="uploadSucccess($event,'changePhoneImg')"></uploadImageOne>
        </el-form-item>

        <el-form-item label="备注:" label-width="60px" prop="remark" class="row">
          <el-input placeholder="请输入备注" type="textarea" rows="3" v-model="ruleForm.remark"></el-input>
        </el-form-item>

      </el-form>

      <div class="center">
        <el-button @click="close('ruleForm')">关闭</el-button>
        <el-button type="primary" @click="submitForm('ruleForm')" :loading="loading">确认</el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import orderApi from "@/api/pickUp/order";
import supplyConfigApi from "@/api/system/supplyConfig";
export default {
  name: "",
  data() {
    return {
      dialogVisible: false,
      loading: false,
      ruleForm: {
        realAccountNumber: "",
        remark: "",
        id: "",
        changeTel: "",
        saleUserId: "",
        changePhoneState: "",
        changePhoneImg:''
      },
      rules: {
        realAccountNumber: [
          { required: true, message: "请输入真实游戏账号", trigger: "blur" },
        ],
      },
      yuangongList: [],
    };
  },
  created() {},
  methods: {
    open(order) {
      this.loading = false;
      this.ruleForm.id = order.id;
      this.ruleForm.remark = order.remark || "";
      this.ruleForm.realAccountNumber = order.realAccountNumber || "";
      this.ruleForm.changeTel = order.changeTel || "";
      this.ruleForm.saleUserId = order.saleUserId || "";
      this.ruleForm.changePhoneState = order.changePhoneState || "";
      this.ruleForm.changePhoneImg = order.changePhoneImg || "";
      this.dialogVisible = true;
      this.getYuangongList();
    },
    // 获取所有员工列表
    getYuangongList() {
      supplyConfigApi
        .getAllUserList({
          userNewType: 1,
        })
        .then((res) => {
          this.yuangongList = res.rows;
        });
    },
    // 选择销售人
    buyerChange(e) {
      if (e) {
        for (let i = 0; i < this.yuangongList.length; i++) {
          if (this.yuangongList[i].userId == e) {
            this.ruleForm.saleUserNickname = this.yuangongList[i].nickName;
          }
        }
      } else {
        this.ruleForm.saleUserNickname = "";
      }
    },
    // 单张图片上传成功
    uploadSucccess(e, key) {
      this.ruleForm[key] = e;
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.loading = true;
          orderApi.changeOrderInfo(this.ruleForm).then((res) => {
            this.dialogVisible = false;
            this.loading = false;
            if (res.code == 200) {
              this.$parent.getList();
            }
          });
        } else {
          //console.log("error submit!!");
          return false;
        }
      });
    },
    close(formName) {
      this.dialogVisible = false;
    },
  },
};
</script>
<style scoped lang="scss">
.demo-ruleForm {
  padding-right: 20px;
}

.center {
  text-align: center;
}

.pick-dialog >>> .el-input--medium input {
  text-align: left;
}
</style>
